//
//  tabV.m
//  爱鲜蜂(郭少乾)
//
//  Created by GuoDeJin on 2016/11/19.
//  Copyright © 2016年 GuoDeJin. All rights reserved.
//

#import "tabV.h"
#import "Masonry.h"
#import "BQFeedbackController.h"
static NSString *cellID = @"cellID";
@interface tabV()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation tabV

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}


-(void)setupUI{
    
    UITableView *tab = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    
    
    [self addSubview:tab];
    
    //数据源 代理
    tab.dataSource = self;
    tab.delegate = self;
    
    //注册cell
    [tab registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    
    [tab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.top.equalTo(self);
        
    }];
   
    //设置cell间距
    tab.sectionHeaderHeight = 5;
    tab.sectionFooterHeight = 5;
    //设置cell最顶端的间距
    tab.contentInset = UIEdgeInsetsMake(-25, 0, 0, 0);
    
    
}

#pragma mark - 数据源方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //如果第1组 返回1行   其他返回2行
    if (section == 1) {
        return 1;
    }
    
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        //第0组第0行
        cell.textLabel.text = @"我的收货地址";
        cell.imageView.image = [UIImage imageNamed:@"v2_my_address_icon"];
        
    }else if(indexPath.section == 0 && indexPath.row == 1){
        //第0组第1行
        cell.textLabel.text = @"店铺收藏";
        cell.imageView.image = [UIImage imageNamed:@"icon_mystore"];
    }else if(indexPath.section == 1){
        //第1组
        cell.textLabel.text = @"把爱鲜蜂分享给朋友";
        cell.imageView.image = [UIImage imageNamed:@"v2_my_share_icon"];
    }else if (indexPath.section == 2 && indexPath.row == 0) {
        //第2组第0行
        cell.textLabel.text = @"客服帮助";
        cell.imageView.image = [UIImage imageNamed:@"online_service"];
        
    }else if(indexPath.section == 2 && indexPath.row == 1){
        //第2组第1行
        cell.textLabel.text = @"意见反馈";
        cell.imageView.image = [UIImage imageNamed:@"v2_my_feedback_icon"];
    }
    //给cell右边添加小箭头
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    //取消cell选中效果
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}




#pragma mark - Cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消cell的选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    
    if([self.delegate respondsToSelector:@selector(cellPushController:withIndexPath:)])
    {
        [self.delegate cellPushController:self withIndexPath:indexPath];
    }
}

@end
